package com.eningqu.aipen.ui.base;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ActivityTestBinding;
import com.eningqu.aipen.logic.network.RxLifecycle;
import com.eningqu.aipen.utils.GlobalConfig;
import com.eningqu.aipen.utils.ScreenUtils;
import com.eningqu.aipen.utils.ToastUtils;
import com.eningqu.aipen.utils.ZKStatusBarUtil;
import com.kongzue.dialogx.dialogs.FullScreenDialog;
import com.kongzue.dialogx.interfaces.OnBindView;

import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;

/**
 * Package:com.eningqu.aipen.ui.base
 * Author:starr
 * Time:2023/11/8 9:52
 * Description: 测试聊天动画
 */
public class TestActivity extends BaseActivity<ActivityTestBinding> {


    public static void startAction(Context context) {
        Intent intent = new Intent(context, TestActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_test;
    }

    @Override
    protected void initView() {
        mBinding.setClick(new TestClick());
    }

    private Button button;


    @SuppressLint("CheckResult")
    @Override
    protected void initData() {
        ZKStatusBarUtil.setTransparentForWindow(this);
        ZKStatusBarUtil.setDarkMode(this);
        button = findViewById(R.id.button);

        TextView width = findViewById(R.id.tvWidth);
        TextView height = findViewById(R.id.tvHeight);
        TextView dpi = findViewById(R.id.tvDpi);

        width.append(ScreenUtils.getScreenWidth() + "");
        height.append(ScreenUtils.getScreenHeight() + "");
        dpi.append(ScreenUtils.getScreenDensityDpi() + "");


        Observable.create(emitter -> {
                    Log.i("TAG", "subscribe: 开始请求");
                    Thread.sleep(5000);
                    Log.i("TAG", "subscribe: 数据请求结束");
                    emitter.onNext("Success");
                    emitter.onComplete();
                })
                .subscribeOn(Schedulers.io())
                .compose(RxLifecycle.bindExLifecycle(this))
                .subscribe(response -> {
                    LogUtils.e(Thread.currentThread());
                    button.setText(response.toString());
                });

        mBinding.checkBox.setOnClickListener(v -> {
            GlobalConfig.isDeBug = mBinding.checkBox.isChecked();
            ToastUtils.showToast(this, "切换环境" + GlobalConfig.isDeBug);
        });

    }


    @SuppressWarnings("all")
    public static class TestClick {
        public void loadDialog(View view) {
            FullScreenDialog.show(new OnBindView<FullScreenDialog>(R.layout.dialog_change) {
                @Override
                public void onBind(FullScreenDialog customDialog, View view) {
                    ImageView ivPic;
                    ivPic = view.findViewById(R.id.iv_pic);
                    Glide.with(view).load("http://8.130.124.187:8088/img/d121b823-d662-4bde-ad94-aef8c41c5b8bbg_word1.jpg").into(ivPic);
                }

            });
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i("TAG", "onPause: ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i("TAG", "onDestroy: ");
    }
}
